package vn.edu.ptithcm.pim.dao;



import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Projections;

import vn.edu.ptithcm.pim.dom.Project;
import vn.edu.ptithcm.pim.util.HibernateUtil;

public class HibernateDao {

	private Session session = null;

	public void openSession() {
		session = HibernateUtil.getSessionFactory().openSession();
		session.beginTransaction();
	}

	public Session getSession() {
		return session;
	}

	public void test() {
		Criteria crit = session.createCriteria(Project.class);
		crit.setProjection(Projections.groupProperty("customer")).addOrder(
				Order.asc("number"));
		System.out.println(crit.list().size());
	}

	public void closeSession() {
		session.getTransaction().commit();
		session.flush();
		session.close();
	}
}
